import serverrun
import threading
import serverdo

#设定服务器地址和端口号
ser_address = ('192.168.2.168',20000)

#创建动态接收命令线程
def  cmdrun():
    print('you can input a letter(d-debug,i-info,w-warn,e-error,f-fatal),to change the log out level,when server run.')
    while True:
        i = input()
        if i is 'd' or i is 'D':
            serverdo.setlogswitch(serverdo.LOG_DEBUG)
            print('log level has been changed to LOG_DEBUG')
        elif i is 'i' or i is 'I':
            serverdo.setlogswitch(serverdo.LOG_INFO)
            print('log level has been changed to LOG_INFO')
        elif i is 'w' or i is 'W':
            serverdo.setlogswitch(serverdo.LOG_WARN)
            print('log level has been changed to LOG_WARN')
        elif i is 'e' or i is 'E':
            serverdo.setlogswitch(serverdo.LOG_ERROR)
            print('log level has been changed to LOG_ERROR')
        elif i is 'f' or i is 'F':
            serverdo.setlogswitch(serverdo.LOG_FATAL)
            print('log level has been changed to LOG_FATAL')
        elif i is 's' or i is 'S':#show connect diction
            serverdo.showsosodict()
        elif i is 'x' or i is 'X':
            serverdo.showsoiddict()
        elif i is 'p' or i is 'P':#show member
            serverdo.showpersondict()
        elif i is 'm' or i is 'M':#show id conn
            serverdo.showfamilydict()
        else:
            pass

#启动日志与动态信息显示交互线程
t = threading.Thread(target=cmdrun)
t.start()

#创建serverdo并且运行
serverdo = serverdo.serverdo((ser_address))
serverdo.setlogswitch(serverdo.LOG_DEBUG)
serverdo.server_run()
